"use strict";
cc._RF.push(module, '20625EdKXNFJaKL4HTixJvn', 'GameEvent');
// script/libs/GameEvent.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameEvent = void 0;
var GameEvent = /** @class */ (function () {
    function GameEvent() {
    }
    /**
     * 监听事件
     * @param event 事件名
     * @param callback 回调
     * @param object 订阅对象
     */
    GameEvent.on = function (event, callback, object) {
        if (!this.events[event])
            this.events[event] = [];
        this.events[event].push({ callback: callback, object: object });
    };
    /**
     * 监听事件（一次性）
     * @param event 事件名
     * @param callback 回调
     * @param object 订阅对象
     */
    GameEvent.once = function (event, callback, object) {
        if (!this.onceEvents[event])
            this.onceEvents[event] = [];
        this.onceEvents[event].push({ callback: callback, object: object });
    };
    /**
     * 取消监听事件
     * @param event 事件名
     * @param callback 回调
     * @param object 订阅对象
     */
    GameEvent.off = function (event, callback, object) {
        if (this.events[event]) {
            for (var i = 0; i < this.events[event].length; i++) {
                if (this.events[event][i].callback === callback && (!object || this.events[event][i].object === object)) {
                    this.events[event].splice(i, 1);
                    i--;
                }
            }
        }
        // 一次性事件
        if (this.onceEvents[event]) {
            for (var i = 0; i < this.onceEvents[event].length; i++) {
                if (this.onceEvents[event][i].callback === callback && (!object || this.onceEvents[event][i].object === object)) {
                    this.onceEvents[event].splice(i, 1);
                    i--;
                }
            }
        }
    };
    /**
     * 发射事件
     * @param event 事件名
     * @param args 参数
     */
    GameEvent.emit = function (event) {
        var args = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            args[_i - 1] = arguments[_i];
        }
        if (this.events[event]) {
            for (var i = 0; i < this.events[event].length; i++) {
                this.events[event][i].callback.apply(this.events[event][i].object, args);
            }
        }
        // 一次性事件
        if (this.onceEvents[event]) {
            for (var i = 0; i < this.onceEvents[event].length; i++) {
                this.onceEvents[event][i].callback.apply(this.onceEvents[event][i].object, args);
            }
            this.onceEvents[event] = [];
        }
    };
    /**
     * 移除事件
     * @param event 事件名
     */
    GameEvent.remove = function (event) {
        if (this.events[event])
            delete this.events[event];
        if (this.onceEvents[event])
            delete this.onceEvents[event];
    };
    /**
     * 移除所有事件
     */
    GameEvent.removeAll = function () {
        this.events = {};
        this.onceEvents = {};
    };
    GameEvent.events = {};
    GameEvent.onceEvents = {};
    return GameEvent;
}());
exports.GameEvent = GameEvent;

cc._RF.pop();